<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\space\controller\findSpace;

use plugin\saiadmin\basic\BaseController;
use app\space\logic\findSpaceLogic;
use app\space\validate\findSpaceValidate;
use support\Request;
use support\Response;

/**
 * 找空间控制器
 */
class findSpaceController extends BaseController
{
    /**
     * 数据表主键
     */
    protected $pk = 'space_id';
    
    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->logic = new findSpaceLogic();
        $this->validate = new findSpaceValidate;
        parent::__construct();
    }

    /**
     * 数据列表
     * @param Request $request
     * @return Response
     */
    public function index(Request $request): Response
    {
       
        $where = $request->more([
            ['lang_code', ''],
            ['space_title', ''],
        ]);
        $query = $this->logic->search($where) ->order('sort_order desc,create_time desc');
        $data = $this->logic->getList($query);
        return $this->success($data);
    }
    public function updateSortOrder(Request $request) : Response
    {
        $id = $request->input('id', '');
        $sort_order = $request->input('sort_order', 1);
       
        $result = $this->logic->where($this->pk, $id)->update(['sort_order' => $sort_order,'update_time'=>date('Y-m-d H:i:s')]);
          
        if ($result) {
            // $this->afterChange('changeStatus');
            return $this->success('操作成功');
        } else {
            return $this->fail('操作失败');
        }
    }
    

}
